<?php
namespace Admin\Controller;


class ArticleController extends AdminController{
	public function index(){
		$article = D('Article','Service');
		$params = array();
		$params['page'] = I('get.p',1);
		$params['step'] =2;
		$res = $article->GetArticleList($params);
		$count = count($res['data']);
		$user = D('User','Service');
		$category = D('Category','Service');
		$userArr['field'] = 'name';
		$categoryArr['field'] = 'name';
		for($i = 0;$i< $count;$i++){
			$userArr['field'] = 'name';
			$userArr['id'] = $res['data'][$i]['uid'];
			$r =$user->GetFieldByid($userArr);
			$res['data'][$i]['uname'] = $r['name'];
			$categoryArr['id'] = (int)$res['data'][$i]['categoryid'];
			$r = $category->GetFieldByid($categoryArr);
			$res['data'][$i]['cname'] = $r['name'];
		}

		$this->assign('data',$res['data']);
		$this->assign('page',$res['page']);
		$this->display();
	}
	public function AddArticle(){
		$category = D('Category','Service');
		$data = $category->GetCategoryByPid(0);
		$_POST['uid'] = $_SESSION['admin']['userInfo']['id'];
		$_POST['display'] = 1;
		$_POST['createtime'] = time();
		$article = D('Article','Service');
		$res = $article->AddArticle();
		if($res['flag']){
			$this->redirect('index');
		}
		$this->assign('data',$data);
		$this->display();
	}
}